#include "ArrayOfList.h"
#include "Dictionary.h"
#include <iostream>
#include <list>
#include <time.h>
using namespace std;

void printList( const list<string> &aList );

void test1();
void test2();
void test3();
void test4();
void test5();
void test6();
void test7();
void test8();
void test9();
void play();


int main() {
    //test1();
    //test2();
    //test3();
    //test4();
    //test5();
    //test6(); //shows that removeAll2 does not work
    //test7(); //shows that removeAll2 does not work
    //test8(); //compares removeAll to removeAll3
    test9(); //compares removeAll to removeAll3
    //play();
    return 0;
}

//prints the list
void printList( const list<string> &aList ) {
    list<string>::const_iterator aListIterator, listEnd;
    aListIterator = aList.begin();
    listEnd = aList.end();
    while( aListIterator != listEnd ) {
        cout << *aListIterator << endl;
        ++aListIterator;
    }
}

//tests to see if ArrayOfList works well enough
//   (sees if operator[] works)
void test1() {
    ArrayOfList<int> theArray;
    theArray[0].push_back(1);
    list<int>::iterator it = theArray[0].begin();
    while( it != theArray[0].end() ) {
        cout << *it << endl;
        ++it;
    }
}

//Sees if Dictionary is able to be set active
//Sees if the active list of dictionary is iterable
void test2() {
    //Dictionary aDictionary("a.txt");
    Dictionary aDictionary("smallList.txt");
    if( aDictionary.setActive(5) == true ) {
        printList( aDictionary.getActiveList() );
    } else {
        cout << "Unable to set dictionary active." << endl;
    }
}

//Sees if multiple sizes can be set active correctly
void test3() {
    //Dictionary aDictionary("a.txt");
    Dictionary aDictionary("smallList.txt");
    for(int i = 0; i < 10; i++) {
        if( aDictionary.setActive(i) == true ) {
            cout << "**** Words of size: " << i << " ****" << endl;
            printList( aDictionary.getActiveList() );
        } else {
            cout << "Unable to set dictionary active." << endl;
        }
    }
}

//sees if removing charaters from list works
void test4() {
    Dictionary aDictionary("smallList.txt");
    if( aDictionary.setActive(5) == true ) {

        cout << "**** Words of size: " << 5 << " ****" << endl;
        printList( aDictionary.getActiveList() );

        for(char aChar = 'a'; aChar <= 'z'; aChar++) {

            cout << "    **** Attempting to remove char: " << aChar << " ****" << endl;
            if( aDictionary.removeAll( aChar ) == false ) {
                cout << "    **** Can not remove char: " << aChar << " ****" << endl;
            } else {
                cout << "    **** Removed char: " << aChar << " ****" << endl;
            }
            printList( aDictionary.getActiveList() );

        }

    } else {
        cout << "Unable to set dictionary active." << endl;
    }
}

//sees if the words that are removed are not lost
void test5() {
    Dictionary aDictionary("smallList.txt");
    if( aDictionary.setActive(5) == true ) {

        cout << "**** Words of size: " << 5 << " ****" << endl;
        printList( aDictionary.getActiveList() );

        for(char aChar = 'a'; aChar <= 'z'; aChar++) {

            cout << "    **** Attempting to remove char: " << aChar << " ****" << endl;
            if( aDictionary.removeAll( aChar ) == false ) {
                cout << "    **** Can not remove char: " << aChar << " ****" << endl;
            } else {
                cout << "    **** Removed char: " << aChar << " ****" << endl;
            }
            printList( aDictionary.getActiveList() );

        }

        cout << "**** Words of size: " << 5 << " ****" << endl;
        aDictionary.deActivate();
        aDictionary.setActive(5);
        printList( aDictionary.getActiveList() );

    } else {
        cout << "Unable to set dictionary active." << endl;
    }
}

void test6() {
    Dictionary aDictionary("Dictionary.txt");
    cout << "Start test" << endl;
    cout<<"choose a size"<<endl;
    int size,guess=0;
    cin>>size;
    if( aDictionary.setActive(size) == true ) {
        char aChar;
        time_t start, stop;
        cout<<"choose a char"<<endl;
        cin >> aChar;

        cout << "Active size before: " << aDictionary.getActiveList().size() << endl;
        start = time(NULL);
        aDictionary.removeAll(aChar);
        stop = time(NULL);
        cout << "time for removeAll:  " << difftime(stop, start) << endl;
        aDictionary.deActivate();
        aDictionary.setActive(size);
        cout << "Active size after: " << aDictionary.getActiveList().size() << endl;
        cout << endl;
        cout << "Active size before: " << aDictionary.getActiveList().size() << endl;
        start = time(NULL);
        aDictionary.removeAll2(aChar);
        stop = time(NULL);
        cout << "time for removeAll2: " << difftime(stop, start) << endl;
        aDictionary.deActivate();
        aDictionary.setActive(size);
        cout << "Active size after: " << aDictionary.getActiveList().size() << endl;
        cout << endl;
        cout << "Active size before: " << aDictionary.getActiveList().size() << endl;
        start = time(NULL);
        aDictionary.removeAll3(aChar);
        stop = time(NULL);
        cout << "time for removeAll3: " << difftime(stop, start) << endl;
        aDictionary.deActivate();
        aDictionary.setActive(size);
        cout << "Active size after: " << aDictionary.getActiveList().size() << endl;
        aDictionary.deActivate();
    } else {
        cout << "Unable to set dictionary active." << endl;
    }
    cout << "Stop test" << endl;
}

void test7() {
    Dictionary aDictionary("Dictionary.txt");
    cout << "Start test" << endl;
    cout<<"choose a size"<<endl;
    int size,guess=0;
    cin>>size;
    if( aDictionary.setActive(size) == true ) {
        char aChar;
        time_t start, stop;
        cout<<"choose a char"<<endl;
        cin >> aChar;
        
        cout << "Active size before: " << aDictionary.getActiveList().size() << endl;
        start = time(NULL);
        aDictionary.removeAll3(aChar);
        stop = time(NULL);
        cout << "time for removeAll3: " << difftime(stop, start) << endl;
        aDictionary.deActivate();
        aDictionary.setActive(size);
        cout << "Active size after: " << aDictionary.getActiveList().size() << endl;
        cout << endl;
        cout << "Active size before: " << aDictionary.getActiveList().size() << endl;
        start = time(NULL);
        aDictionary.removeAll(aChar);
        stop = time(NULL);
        cout << "time for removeAll:  " << difftime(stop, start) << endl;
        aDictionary.deActivate();
        aDictionary.setActive(size);
        cout << "Active size after: " << aDictionary.getActiveList().size() << endl;
        cout << endl;
        cout << "Active size before: " << aDictionary.getActiveList().size() << endl;
        start = time(NULL);
        aDictionary.removeAll2(aChar);
        stop = time(NULL);
        cout << "time for removeAll2: " << difftime(stop, start) << endl;
        aDictionary.deActivate();
        aDictionary.setActive(size);
        cout << "Active size after: " << aDictionary.getActiveList().size() << endl;
        aDictionary.deActivate();
    } else {
        cout << "Unable to set dictionary active." << endl;
    }
    cout << "Stop test" << endl;
}

void test8() {
    Dictionary aDictionary("Dictionary.txt");
    cout << "Start test" << endl;
    int size;
    do {
        cout<<"choose a size"<<endl;
        cin>>size;
        if( size != 0 && aDictionary.setActive(size) == true ) {
            char aChar;
            time_t start, stop;
            do {
                cout<<"choose a char"<<endl;
                cin >> aChar;
                if(aChar != '0') {
                    start = time(NULL);
                    aDictionary.removeAll(aChar);
                    stop = time(NULL);
                    cout << "time for removeAll:  " << difftime(stop, start) << endl;
                    aDictionary.setActive(size);
                    start = time(NULL);
                    aDictionary.removeAll3(aChar);
                    stop = time(NULL);
                    cout << "time for removeAll3: " << difftime(stop, start) << endl;
                    //aDictionary.setActive(size);
                }
            } while(aChar != '0');
        } else {
            cout << "Unable to set dictionary active." << endl;
        }
    } while(size != 0);
    cout << "Stop test" << endl;
}

void test9() {
    Dictionary aDictionary("Dictionary.txt");
    cout << "Start test" << endl;
    int size;
    do {
        cout<<"choose a size"<<endl;
        cin>>size;
        if( size != 0 && aDictionary.setActive(size) == true ) {
            char aChar;
            clock_t start, stop;
            do {
                cout<<"choose a char"<<endl;
                cin >> aChar;
                if(aChar != '0') {
                    start = clock();
                    aDictionary.removeAll(aChar);
                    stop = clock();
                    cout << "clocks for removeAll:  " << (stop-start) << endl;
                    aDictionary.setActive(size);
                    start = clock();
                    aDictionary.removeAll3(aChar);
                    stop = clock();
                    cout << "clocks for removeAll3: " << (stop-start) << endl;
                    aDictionary.setActive(size);
                    start = clock();
                    aDictionary.removeAll4(aChar);
                    stop = clock();
                    cout << "clocks for removeAll4: " << (stop-start) << endl;
                    //aDictionary.setActive(size);
                }
            } while(aChar != '0');
        } else {
            cout << "Unable to set dictionary active." << endl;
        }
    } while(size != 0);
    cout << "Stop test" << endl;
}

void play() {
    Dictionary aDictionary("Dictionary.txt");
    cout<<"choose a size"<<endl;
    int size,guess=0;
    cin>>size;
    if( aDictionary.setActive(size) == true ) {

        cout << "**** Words of size: " << size << " ****" << endl;
        //printList( aDictionary.getActiveList() );

        //for(char aChar = 'a'; aChar <= 'z'; aChar++) {
        char aChar;
        while(cin>>aChar&&aChar!='1'){

            cout<<"Guess #"<<++guess<<endl;
            cout<<"Picked:"<<aChar<<endl;
            //cout << "    **** Attempting to remove char: " << aChar << " ****" << endl;
            if( aDictionary.removeAll2( aChar ) == false ) {
                //cout << "    **** Can not remove char: " << aChar << " ****" << endl;
            } else {
               // cout << "    **** Removed char: " << aChar << " ****" << endl;
            }
            //printList( aDictionary.getActiveList() );
            cout<<"word is: |"<<aDictionary.getWord()<<"|"<<endl;

        }

        cout << "**** Words of size: " << size << " ****" << endl;
        aDictionary.deActivate();
        aDictionary.setActive(size);
        printList( aDictionary.getActiveList() );

    } else {
        cout << "Unable to set dictionary active." << endl;
    }
}
